import type { PlatformTypeValue } from '../../../../types/interfaces'

export interface DiscussionAnalyticsConfig {
  selector: string
  authorUrl: string
  authorName: string
  avatar: string
  postTime: string
  roleIndicator: {
    originalPoster: string
    author: string
    admin: string
    deletedUser: string
  }
  button: string
}
export type DiscussionAnalyticsPlatformConfig = Partial<Record<PlatformTypeValue, Record<string, DiscussionAnalyticsConfig>>>

export enum DiscussionUserRole {
  OriginalPoster = 'OriginalPoster',
  Author = 'Author',
  Admin = 'Admin',
  RegularUser = 'RegularUser',
  DeletedUser = 'DeletedUser',
}

export type DiscussionUserRoleFilter = DiscussionUserRole | 'all'

export enum DiscussionUserRoleBadge {
  OriginalPoster = '🫅 楼主',
  Author = '‍👨‍💻 作者',
  Admin = '👮 管理员',
  RegularUser = '👩‍🚀 用户',
  DeletedUser = '🚫 已注销',
}

export enum DiscussionActivityLevel {
  High = 'high',
  Medium = 'medium',
  Low = 'low',
}

export interface DiscussionCommentData {
  id: string
  floorNumber: number
  user: {
    name: string
    url: string
    avatar: string
    isOriginalPoster: boolean
    isAuthor: boolean
    isAdmin: boolean
    isDeletedUser: boolean
  }
  timestamp: string
  timestampMs: number
  role: DiscussionUserRole
}

export interface DiscussionTimeDistribution {
  byHour: Record<string, number>
  byDay: Record<string, number>
  byWeekday: Array<number>
}

export type DiscussionRoleBasedData = Partial<Record<DiscussionUserRole, {
  timeDistribution: DiscussionTimeDistribution
  activityPeaks: Array<{ hour: number, count: number }>
  commentCount: number
  userCount: number
}>>

export interface DiscussionUserStats {
  name: string
  url: string
  avatar: string
  floorNumbers: number[]
  commentCount: number
  role: DiscussionUserRole
  firstCommentTime: number
  lastCommentTime: number
}

export interface DiscussionDuration {
  start: string
  end: string
  durationHours: number
}

export interface DiscussionUserRolesDistribution {
  [DiscussionUserRole.OriginalPoster]: number
  [DiscussionUserRole.Author]: number
  [DiscussionUserRole.Admin]: number
  [DiscussionUserRole.RegularUser]: number
  [DiscussionUserRole.DeletedUser]: number
}

export interface DiscussionTimeMetrics {
  averageInterval: number // 平均发布间隔（天）
  maxInterval: number // 最长发布间隔
  minInterval: number // 最短发布间隔
  slowestCommentId: string // 最慢回复评论 ID
  fastestCommentId: string // 最快回复评论 ID
  firstCommentTime: string // 最早发布时间
  lastCommentTime: string // 最新发布时间
  hoursSinceLastUpdate: number // 多久没更新（小时）
  commentFrequency: number // 评论频率（条/周）
  isActive: boolean // 是否活跃（最近 24 小时有更新）
  activityLevel: DiscussionActivityLevel // 活跃度等级
}

export interface DiscussionAnalyticsData {
  totalComments: number
  uniqueParticipants: number
  userRoles: DiscussionUserRolesDistribution
  timeDistribution: DiscussionTimeDistribution
  userRankings: DiscussionUserStats[]
  activityPeaks: Array<{ hour: number, count: number }>
  roleBasedData: DiscussionRoleBasedData
  averageCommentsPerUser: number
  mostActiveUser: DiscussionUserStats | null
  discussionDuration: DiscussionDuration
  timeMetrics: DiscussionTimeMetrics
  heatScore?: number
  heatColor?: string
  heatIcon?: string
}
